package com.sizu.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.common.dto.RoleDto;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.TRoleMenu;
import com.sizu.service.ITRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-22
 */
@RestController
@RequestMapping("/user/tRoleMenu")
public class TRoleMenuController {

    @Autowired
    private ITRoleMenuService itRoleMenuService;


    @RequestMapping("/up")
    public ResultEntity tRoleMenuUp(RoleDto roleDto){
        Wrapper<TRoleMenu> wrapper=new EntityWrapper<>();
        wrapper.eq("role_id",roleDto.getId());
        itRoleMenuService.delete(wrapper);
        if(roleDto.getMenuIds().length!=0){
            for (Integer menuId : roleDto.getMenuIds()) {
                TRoleMenu tRoleMenu=new TRoleMenu();
                tRoleMenu.setRoleId(roleDto.getId());
                tRoleMenu.setMenuId(menuId);
                itRoleMenuService.insert(tRoleMenu);
            }
        }
        return ResultEntity.ok("修改成功");
    }
}
